//
//  POIModel.swift
//  travelMap
//
//  Created by green on 15/6/30.
//  Copyright (c) 2015年 com.city8. All rights reserved.
//

import UIKit
import JSONHelper

// POI
public class POIModel: NSObject, Deserializable {
    
    var poiId: String?              // ID
    var poiName: String?            // 名称
    var poiPicUrl: NSURL?           // 图片地址
    var score: Int = random()%100   // 评分
    var level: Int = random()%5+1   // 星级
    var desc: String?               // 简介
    var address: String?            // 地址
    var openTime: String?           // 开放时间
    var ticketPrice: Int?        // 票价
    var longitude: Double?          // 经度
    var latitude: Double?           // 纬度
    var poiType: Int?            // POI类型
    var country: String?            // 国家
    var cityName: String?           // 城市
    var cityEnName: String?         // 城市英文
    
    var poiPhotoInfo: PhotoInfo?
    
    override init() { }
    
    required public init(data : [String:AnyObject]) {
        
        super.init()
        
        poiId           <-- data["poiId"]
        poiName         <-- data["poiName"]
        poiPicUrl       <-- data["poiPicUrl"]
        score           <-- data["score"]
        level           <-- data["level"]
        desc            <-- data["des"]
        address         <-- data["address"]
        openTime        <-- data["openTime"]
        ticketPrice     <-- data["ticketPrice"]
        longitude       <-- data["longitude"]
        latitude        <-- data["latitude"]
        poiType         <-- data["poiType"]
        country         <-- data["countryName"]
        cityName        <-- data["cityName"]
        cityEnName      <-- data["cityEnName"]
        
        if let poiPicUrl=poiPicUrl {
            
            poiPhotoInfo = PhotoInfo(sourceImageURL: poiPicUrl)
        }
        
        self.favoritePoiExtraBlock(data)
    }

    func favoritePoiExtraBlock(data : [String:AnyObject]) {
        
        if poiId == nil {
            
            var poiId:Int?
            poiId <-- data["poiId"]
            self.poiId = String(poiId)
        }
        
        if poiName == nil {
            poiName <-- data["poiNameCn"]
        }
        if poiPicUrl == nil {
            poiPicUrl <-- data["picUrl"]
        }
    }
    
    override public var description: String {
        
        get {
            
            return "poiId:\(poiId) \n poiName:\(poiName) \n poiPicUrl:\(poiPicUrl) \n score:\(score) \n level:\(level) \n desc:\(desc) \n address:\(address) \n openTime:\(openTime) \n ticketPrice:\(ticketPrice) \n longitude:\(longitude) \n latitude:\(latitude) \n poiType:\(poiType) \n country:\(country) \n cityName:\(cityName) \n cityEnName:\(cityEnName) \n --------------------------------------------------------------------- \n "
        }
    }
}

